#ifndef __STUN_REQUEST_H
#define __STUN_REQUEST_H
#include <map>
#include <rtc_base/third_party/sigslot/sigslot.h>
#include "ice/stun.h"
namespace xrtc
{

    class StunRequest;

    class StunRequestManager : public sigslot::has_slots<>
    {

    public:
        StunRequestManager() = default;
        ~StunRequestManager();
        void Send(StunRequest *request);
        sigslot::signal3<StunRequest *, const char *, size_t> SignalSendPacket;
        bool CheckResponse(StunMessage *msg);
        void Remove(StunRequest *request);

    private:
        typedef std::map<std::string, StunRequest *> RequestMap;
        RequestMap requests_;
    };
    class StunRequest
    {
    public:
        StunRequest(StunMessage *msg);
        virtual ~StunRequest();
        const std::string &Id() { return msg_->TranscationId(); }
        void Construct();
        void Send();
        void SetManager(StunRequestManager *manager) { manager_ = manager; }
        int Type() { return msg_->Type(); }
        int Elapsed();

    protected:
        virtual void Prepare(StunMessage *) {};
        virtual void OnRequestResponse(StunMessage *) {};
        virtual void OnRequestErrorResponse(StunMessage *) {};
        friend class StunRequestManager;

    private:
        StunMessage *msg_;
        StunRequestManager *manager_ = nullptr;
        int64_t ts_ = 0;
    };

} // namespace xrtc;

#endif